package cn.wei.sdd.core.controller.admin;


import cn.wei.common.result.R;
import cn.wei.sdd.base.util.JwtUtils;
import cn.wei.sdd.core.enums.ExamineStatusEnum;
import cn.wei.sdd.core.pojo.entity.Examine;
import cn.wei.sdd.core.pojo.entity.User;
import cn.wei.sdd.core.pojo.query.UserQuery;
import cn.wei.sdd.core.service.ExamineService;
import cn.wei.sdd.core.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * <p>
 * 回收员审核表 前端控制器
 * </p>
 *
 * @author Wei
 * @since 2021-10-22
 */
@Api(tags = "回收员管理")
//@CrossOrigin //跨域
@RestController
@RequestMapping("/admin/core/examine")
public class AdminExamineController {

    @Autowired
    private ExamineService examineService;

    @Autowired
    private UserService userService;


    @ApiOperation("获取申请分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码",required = true)
            @PathVariable Long page,
            @ApiParam(value = "每页记录数",required = true)
            @PathVariable Long limit,
            @ApiParam(value = "查询关键字",required = false)
                    String keyword){

        Page<Examine> pageParam = new Page<>(page,limit);
        IPage<Examine> pageModel = examineService.listPage(pageParam,keyword);

        return R.ok().data("pageModel",pageModel);
    }



    @ApiOperation("回收员审批认证")
    @PostMapping("examine/{examineId}/{status}/{getRate}")
    public R examine(
            @ApiParam(value = "审批状态",required = true)
            @PathVariable("status") Integer status,
            @ApiParam(value = "审批id",required = true)
            @PathVariable("examineId") Long examineId,
            @PathVariable("getRate") BigDecimal getRate,
            HttpServletRequest request){

        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        examineService.examine(examineId,status,userId,getRate);
        return R.ok().message(status==ExamineStatusEnum.AUTH_OK.getStatus()?"审核通过":"取消认证");
    }

}

